package com.service.core.constant;

import org.springframework.lang.Nullable;

/**
 * 全局业务状态码
 * 格式：10xxxx
 */
public enum BusinessStatus {

    /**
     * 状态枚举
     */

    USER_NAME_OR_PASSWORD_ERROR(100001, "用户名或者密码错误"),

    ORIGINAL_PASSWORD_ERROR(100002, "原始密码错误"),

    NEW_PASSWORD_NOT_EQUAL(100003, "新密码不一致"),

    TOKEN_ERROR(100004, "TOKEN错误"),

    EXISTED_LOGIN_NAME(100005, "登录名已经存在"),

    INVALID_USER_STATUS(100006, "无效的用户状态"),

    NOT_SUPPORT_FILE_TYPE(100007, "不支持的文件类型"),

    INVALID_SERVICE_NAME(100008, "无效的服务名称"),

    DELETE_SELF_ERROR(100009, "不允许删除自身账号"),

    DELETE_CONTAIN_CHILD_MENU_ERROR(100010, "不允许删除包含子菜单的菜单"),

    DELETE_BUILD_IN_SYSTEM_ERROR(100011, "系统内置不可删除"),

    PARENT_MENU_PERMISSION_NOT_FOUND(100012, "父菜单不存在"),

    EXISTED_IDENTIFIER(100013, "已经存在的IDENTIFIER"),

    TOKEN_GENERATION_EXCEPTION(100014, "生成TOKEN异常"),

    PHONE_ALREADY_REGISTERED(100018, "该手机号已注册"),

    INVALID_PICTURE_VALIDATION_CODE(100019, "图形验证码验证码错误"),

    INVALID_SMS_VERIFY_CODE(100020, "短信验证码无效"),

    MAX_COUNT_PER_IP_EXP(100021, "此ip申请验证码数量已达当日上限"),

    MAX_COUNT_PER_PHONE_EXP(100022, "此手机号申请验证码数量已达当日上限"),

    MIN_DURATION_EXP(100023, "此手机申请验证码间隔不足最短时间间隔"),

    EXPIRED_SMS_VERIFY_CODE(100024, "短信验证码已过期"),

    ERROR_SMS_VERIFY_CODE(100025, "短信验证码错误"),

    NOT_FOUND_USER(100026, "用户不存在"),

    NOT_FOUND_CIRCLE_ORDER(100030, "订单不存在"),

    CURRENT_USER_NO_POWER(10037, "当前用户无此权限"),

    SAFETY_PWD_ERROR(100000, "支付密码错误"),

    ARGS_ERROR(10044, "args_error"),

    ALREADY_SIGN(10045, "今日已签到"),

    END(109999, "结束");

    /**
     * 内部变量和方法
     */

    private final int value;

    private final String reasonPhrase;

    BusinessStatus(int value, String reasonPhrase) {
        this.value = value;
        this.reasonPhrase = reasonPhrase;
    }

    public int value() {
        return this.value;
    }

    public String getReasonPhrase() {
        return this.reasonPhrase;
    }

    @Override
    public String toString() {
        return Integer.toString(this.value);
    }

    public static BusinessStatus valueOf(int statusCode) {
        BusinessStatus status = resolve(statusCode);
        if (status == null) {
            throw new IllegalArgumentException("No matching constant for [" + statusCode + "]");
        }
        return status;
    }

    @Nullable
    public static BusinessStatus resolve(int statusCode) {
        for (BusinessStatus status : values()) {
            if (status.value == statusCode) {
                return status;
            }
        }
        return null;
    }

}
